#include "mainscene.h"
#include "ui_mainscene.h"
#include "gameconfig.h"
#include "gamecontroller.h"
#include "gamepushbutton.h"


#include <QPaintEvent>
#include <QPixmap>
#include <QPainter>
#include <QDebug>
#include <QTimer>




MainScene::MainScene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainScene)
{
    ui->setupUi(this);
    this->setWindowTitle("翻转金币游戏");
    this->setFixedSize(GAME_WIDTH,GAME_HEIGHT);//设置固定大小
    this->setWindowIcon(QIcon(IMG_GAME_ICON));//在窗口体台头添加图片(包括任务栏图标)

    //初始化单例
    GameController::getInstance()->initMainScene(this);


    //
    GamePushButton *btnStart = new GamePushButton(BMG_START_GAME,"");
    btnStart->setParent(this);
    btnStart->move((GAME_WIDTH-btnStart->width())/2,GAME_HEIGHT-btnStart->height()-150);

    connect(btnStart,&GamePushButton::clicked,this,[=]()
    {
        GameController::getInstance()->playStarsSound();
        qDebug()<<"clicked btnStart";
        //实现按钮的上下弹跳
        btnStart->zoomUp();
        btnStart->zoomDown();
        QTimer::singleShot(700,this,[=]()
        {

            GameController::getInstance()->hideMianScene();
            GameController::getInstance()->showLevelScene();
        });


    });



}

MainScene::~MainScene()
{
    delete ui;
}


void MainScene::on_actionquit_triggered()
{
    exit(0);

}


//添加画家
void MainScene::paintEvent(QPaintEvent *event)
{
    QPainter mainPaiter(this);//创建画家
    QPixmap mainPixmap;//创建图片
    bool ret = mainPixmap.load(IMG_BG_MAINSCENE);//图片插入pixmap
    if(ret)
    {
        mainPaiter.drawPixmap(0,0,mainPixmap);//通过画家绘制出图片
    }
}









